#ifndef RECEIVEWINDOW_H_
#define RECEIVEWINDOW_H_

#include "stdGNUTDefs.h"
#include "Packet.h"

class ReceiveWindow
{
private:
	unsigned int myWindowSize;
	unsigned int leftWindowEdge;
	unsigned int bytesWritten;
	int myFd;
	bool alive;
	GNUT_dataBlock_t* tail;
	GNUT_dataBlock_t* head;
	
	void slide();
	bool detectCollision(unsigned int packetSeqNo, GNUT_dataBlock_t**);
	int clipPacket(Packet &p);
	
	
public:
	ReceiveWindow();
	ReceiveWindow(unsigned int windowSize);
	virtual ~ReceiveWindow();
	
	void setTargetFile(int fd);
	void setISN(unsigned int isn);
	void addPacket(Packet p);
	GNUT_dataBlock_t* createDataBlock(Packet p);
	void addDataBlock(GNUT_dataBlock_t* dataBlock);
	int getBytesWritten();
	int getLeftWindowEdge();
	bool isAlive();
	int getRemainingWindowSize();
	int printWindowState();
	void clear();
};

#endif /*RECEIVEWINDOW_H_*/
